<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		
		<meta charset="utf-8" />
		<title></title>
		
		<meta name="description" content="overview & stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link href="static/css/bootstrap.min.css" rel="stylesheet" />
		<link href="static/css/bootstrap-responsive.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="static/css/font-awesome.min.css" />
		<link rel="stylesheet" href="static/css/ace.min.css" />
		<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
		<link rel="stylesheet" href="static/css/ace-skins.min.css" />
		
		<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
		<!--提示框-->
		<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</head>

<body>
	<form  action="marketmanager/edit.do" name="Form" id="Form" method="post">
		<input type="hidden" name="m_id" id="m_id" value="${pd.m_id }" />
		<input type="hidden" name="organ_id" id="organ_id" value="${pd.organ_id }" />
		<input type="hidden" name="current_organ_id" id="current_organ_id" value="${pd.current_organ_id }" />
		<div id="centerOfMainFrame">
		<table>
			<tr class="info">
				<td>指定操作:</td>
				<td>
					<select id="operatorType" name="operatorType">
						<option value="0"  <c:if test="${pd.operatorType == 0 }">selected</c:if> >取消设置</option>
						<option value="1"  <c:if test="${pd.operatorType == 1 }">selected</c:if> >设置为营销经理</option>
					</select>	
				</td>
			</tr>
			<tr>
				<td style="text-align: center;" colspan="2">
					<a class="btn btn-mini btn-primary" onclick="save_members();">保存</a>
					<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
					<input type="hidden" id="m_id" name="m_id" value="${pd.m_id}"/>
				</td>
			</tr>
		</table>
		</div>
		<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><img src="static/images/jzx.gif" style="width: 50px;" /><br/><h4 class="lighter block green"></h4></div>
	</form>
	
</body>

<script type="text/javascript">
	$(top.hangge());
	var result = false;
	function tocheckname() {
		var m_id = $("#m_id").val();
		$.ajax({
			type : "PUT",
			url : "marketmanager/hasMarketmanage/"+m_id+ ".json",
			//data:JSON.stringify(catacode),
			contentType:"application/json",  //发送至服务器的类型
			dataType : "json",     //预期服务器返回类型
			success: function(data){
				//alert(data.string);
				//return false;
				if(data.string=="error"){
					//alert("此用户已设置为营销经理，请先取消设置！");
					$("#operatorType").tips({
						side : 3,
						msg : '此用户已设置为营销经理，请先取消设置！',
						bg : '#AE81FF',
						time : 3
					});
					$("#operatorType").focus();
					result = false;
				}else{
					result = true;
					if(result){
						$("#Form").submit();
						$("#centerOfMainFrame").hide();
						$("#centerOfMainFrame2").show();
					}
				}
			}
		})
	}
	
	//保存
	function save_members(){
		var organ_id = $("#organ_id").val();
		var current_organ_id = $("#current_organ_id").val();
		
		var operatorType = $("#operatorType").val();
		if(operatorType == 0){
			if(organ_id == null || organ_id == ""){
				$("#operatorType").tips({
					side : 3,
					msg : '当前用户不能取消设置！',
					bg : '#AE81FF',
					time : 3
				});
				$("#operatorType").focus();
				result = false;
			}else if(organ_id != null && organ_id != "" && organ_id != current_organ_id){
				$("#operatorType").tips({
					side : 3,
					msg : '当前操作员无权取消设置！',
					bg : '#AE81FF',
					time : 3
				});
				$("#operatorType").focus();
				result = false;
			}else{
				result = true;
				if(result){
					$("#Form").submit();
					$("#centerOfMainFrame").hide();
					$("#centerOfMainFrame2").show();
				}
			}
		}else{
			tocheckname();
		}
		//setTimeout("top.Dialog.close()",100);
	}
	
</script>

</html>